package com.rabbitmq.consumer.ttl;

import com.google.gson.reflect.TypeToken;
import com.rabbitmq.consumer.entity.Order;
import com.rabbitmq.consumer.utils.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * @Author: Thomas
 * @Date: 2024-01-20  20:47:40
 * @Description:
 */
@Service
@RabbitListener(queues = {"fanout.ttl.2.queue"})
@Slf4j
public class TTL02Consumer {

    @RabbitHandler
    public void getMessage(String message) throws InterruptedException {
        log.info("email: {}", message);
        Order order = JSONUtil.fromJson(message,  new TypeToken<Order>() {}.getType());
        log.info("email: {} -- {}", System.identityHashCode(order), order.toString());
        Thread.sleep(20000);
    }

}

